<?php
namespace Lisheng\HiAdmin\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use Lisheng\HiAdmin\Models\Permission;
class PermissionController{

	public function index()
	{
		$permissions = Permission::get()->toArray();

		return view('admin.users.permissions')->with('permissions',$permissions);
	}

	public function create()
	{
		return view('admin.users.permissionscreate');
	}
	
	public function postPermission(Request $request){

		$permissionInfo = $request->only(['name','code']);

		$validator = Validator::make($permissionInfo,[
				'name'=>'required',	
				'code'=>'required'
			]);

		if($validator->fails()){
			return response()->json(['code'=>'-1','msg'=>'内容不能为空']);
		}

		if(Permission::create($permissionInfo))
		{
	 	 return response()->json(['code'=>'0','msg'=>'添加成功']);
		}
	}

	
}